﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using Olitee.WorkScheduler.Interfaces;
using Olitee.WorkScheduler.Model;

namespace Olitee.WorkScheduler.Service
{
    /// <summary>
    /// This simple scheduler service wraps an instance of the scheduelr, and exposes an interface for WCF.
    /// </summary>
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class SchedulerService : ISchedulerService
    {
        private Scheduler scheduler;

        public SchedulerService()
        {
            scheduler = new Scheduler();

            // Add your scheduler configuration here ...

            
        }

        public void AddWorkItem(WorkItemBase workItem)
        {
            scheduler.AddWorkItem(workItem);
        }

        public void StartScheduler()
        {
            scheduler.StartScheduler();
        }

        public void StopScheduler()
        {
            scheduler.StopScheduler();
        }

        public List<WorkScheduler.Model.WorkItemBase> GetAllJobs()
        {
            List<WorkItemBase> baseWorkItems = new List<WorkItemBase>();
            scheduler.AllWorkItems.ForEach(wi => baseWorkItems.Add((WorkItemBase)wi));
            return baseWorkItems;
        }

        public void SetMaximumConcurrentWorkItems(int concurrency)
        {
            scheduler.MaximumConcurrentWorkProcesses = concurrency;
        }


    }
}
